package com.zhongxi.guoyuan.adapter.beautifulStore;

import android.content.Context;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.service.ServiceItemData;
import com.zhongxi.guoyuan.url.Url;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/10/17.
 */

public class NewBeautifulAdapter extends BaseAdapter {
    private List<ServiceItemData> data;
    private Context context;

    public NewBeautifulAdapter(Context context, List<ServiceItemData> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        if (data != null && data.size() > 0) {
            return data.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            view = View.inflate(context, R.layout.item_project, null);
            vh = new ViewHolder(view);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        ServiceItemData list = data.get(i);
        Glide.with(context).load(Url.IMG_URL + list.getThumbnail()).placeholder(R.mipmap.iv_loading).fitCenter().into(vh.ivImg);
        if (null != list.getName() && !"".equals(list.getName())) {
            vh.tvText.setText(list.getName().trim());
        } else {
            vh.tvText.setText("");
        }


        if(null!=list.getRedbeanprice()&&!"".equals(list.getRedbeanprice())){
            vh.tvPriceDiy.setText("+"+list.getRedbeanprice()+"红豆");
        }else{
            vh.tvPriceDiy.setText("");
        }
        if (null != list.getInnerprice() && !"".equals(list.getInnerprice())) {
            vh.tvCash.setText(list.getInnerprice() + " 美豆");
        } else {
            vh.tvCash.setText("0 美豆");
        }
        if (null != list.getMarketprice() && !"".equals(list.getMarketprice())) {
            vh.tvOriginPrice.setText("市场价 ：" + list.getMarketprice()+"元");
            vh.tvOriginPrice.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        } else {
            vh.tvOriginPrice.setText("");
        }
        if (null != list.getViewnum() && !"".equals(list.getViewnum())) {
            vh.tvView.setText(list.getViewnum());
        } else {
            vh.tvView.setText("");
        }
        if (null != list.getServicetime() && !"".equals(list.getServicetime())) {
            vh.tvTime.setText(list.getServicetime() + " 分钟");
        } else {
            vh.tvTime.setText("");
        }
        return view;
    }

    static class ViewHolder {
        @Bind(R.id.ivImg)
        ImageView ivImg;
        @Bind(R.id.tv_time)
        TextView tvTime;
        @Bind(R.id.tvText)
        TextView tvText;
        @Bind(R.id.tvView)
        TextView tvView;
        @Bind(R.id.tv_price_diy)
        TextView tvPriceDiy;
        @Bind(R.id.tvOriginPrice)
        TextView tvOriginPrice;
        @Bind(R.id.tvCash)
        TextView tvCash;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
